<?php

namespace base;

use Yii;

use yii\web\View;


use yii\widgets\LinkPager;

/**
 * Site controller
 */
class BaseView extends View
{

	private $_cachedRoles;
    public $root_dir;
	
	
	public function init(){
	    parent::init();
		$this->root_dir = dirname(Yii::getAlias('@web'));
		Yii::setAlias('wwwroot', $this->root_dir);
		//exit(Yii::getAlias('@wwwroot'));
		//exit($this->root_dir);
		//exit(Yii::getAlias('@runtime'));
		//exit(\Yii::$app->request->baseUrl);
		//exit(\Yii::$app->urlManager->createUrl(['site/page', 'id' => 'about']));
		
	}
	
	
	public function createUrl($route){
		return Yii::$app->urlManager->createUrl($route);
		
	}
	
	public function formUrl($model, $params = []){
		if ($model->isNewRecord){
			$route = [$this->context->id.'/create'];
		}else{
			$key = $model->primaryKey()[0];
			$route = [$this->context->id.'/update', $key => $model->$key];
		}
		return Yii::$app->urlManager->createUrl(array_merge($route, $params));
		
	}
	
	
	public function getId(){
		return Yii::$app->requestedAction->id;
	}
	
	public function linkPager($pages){
		
        echo $pages->totalCount ? LinkPager::widget(['pagination' => $pages]) : '';
	}
	
	public function csrfToken($input = true){
		return \base\YiiMobo::csrfToken($input);
	}
	

}
